import frappe
from frappe.auth import LoginManager

@frappe.whitelist(allow_guest=True)
def supplier_login(supplier_username,supplier_password):
    login_manager = LoginManager()
    try:
        login_manager.authenticate(supplier_username, supplier_password)
    except Exception as e:
        print("An exception occurred: ", e)
        return {"code": 600, "message": "登录失败!","home_page": "login"}
    login_manager.post_login()
    print(frappe.response['message'])
    if frappe.response['message'] == 'Logged In':
        return {"code": 200, "message": "登录成功!", "home_page": "app"}
    else:
        return {"code": 600, "message": "登录失败!","home_page": "login"}